# -*- coding:utf-8 -*-
import socket

udp_client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

qq_name_dic = {
    '乔治': ('127.0.0.1', 8081),
    'james': ('127.0.0.1', 8082),
    '苯环': ('127.0.0.1', 8083),
    '岳岳': ('127.0.0.1', 8084),
}

while True:
    qq_name = input('请选择聊天对象: ').strip()
    if not qq_name or qq_name not in qq_name_dic:
        continue
    while True:
        msg = input('请输入消息,回车发送: ').strip()
        if msg == 'quit':
            break
        if not msg:
            continue
        udp_client_socket.sendto(msg.encode('utf-8'), qq_name_dic[qq_name])

        back_msg, addr = udp_client_socket.recvfrom(1024)
        print('来自[%s:%s]的一条消息:%s' % (addr[0], addr[1], back_msg.decode('utf-8')))
